<script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3.exp&sensor=false&language=th"></script>
<style type="text/css">  
/* css กำหนดความกว้าง ความสูงของแผนที่ */  
#map_canvas {   
    height:500px;  
    margin:auto; margin-left:20px; margin-right:20px;
/*  margin-top:100px;*/  
}  
</style>
<script type="text/javascript">
$(document).ready(function(){
      $('#cm_titlename').val("<?php echo $user['cm_titlename'];?>").attr('selected','selected');
      $('#cm_type').val("<?php echo $user['cm_type'];?>").attr('selected','selected');
      $('#cm_package').val("<?php echo $user['cm_package'];?>").attr('selected','selected');
});

</script>
<div id="page-wrapper">
            <div class="row">
            <img src="<?php echo base_url() ?>bootstrap/tot/bnnr-eservice1.jpg" class="img-responsive" alt="Responsive image">
                <!-- /.col-lg-12 -->
            </div>
            <!-- /.row -->
            <div class="row">
                <div class="col-lg-12">
                    <div class="panel panel-primary">
                        <div class="panel-heading">
                            <?=$title;?>
                        </div>
                        <div class="row">
                          
                            <div class="panel-body">
                            <!-- Nav tabs -->
                            <ul class="nav nav-tabs">
                                <li class="active"><a href="#profile" data-toggle="tab">ข้อมูลลูกค้า</a>
                                </li>
                                <li><a href="#map" data-toggle="tab">ข้อมูลแผนที่</a>
                                </li>
                            </ul>
                              <!-- Tab panes -->
                             <form id="customer_form" class="form-horizontal" role="form" method="post" action="<?=$url;?>"  <?=($profile==TRUE ? 'target="_blank"' : '');?>>
                             <br/>
                            <div class="tab-content">
                            <div class="tab-pane fade in active" id="profile">
                                        <div class="form-group">
                                            <label for="inputEmail3" class="col-sm-2 control-label">รหัสลูกค้า</label>
                                            <div class="col-xs-3 col-md4">
                                                <input type="text" class="form-control" name="cm_code" value="<? echo $user['cm_code']?>"  <?=($user['cm_id']) ? 'readonly="readonly"' : ''?>  required>
                                            </div>
                                                <label for="inputPassword3" class="col-sm-2 control-label">หมายเลขติดตั้ง</label>
                                            <div class="col-xs-4 col-md4">
                                                <input type="text" class="form-control" name="cm_lineid" value="<? echo $user['cm_lineid']?>" <?=($user['cm_id']) ? 'readonly="readonly"' : ''?> required>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="inputEmail3" class="col-sm-2 control-label">คำนำหน้าชื่อ</label>
                                                <div class="col-md-2">
                                                    <select class="form-control" id='cm_titlename' name="cm_titlename" value="<? echo $user['cm_titlename']?>" required>
                                                        <option>นาย</option>
                                                        <option>นางสาว</option>
                                                        <option>นาง</option>
                                                    </select>
                                                </div>
                                            <label for="inputEmail3" class="col-sm-2 control-label">ประเภทลูกค้า</label>
                                                <div class="col-md-2">
                                                    <select class="form-control" id='cm_type' name="cm_type"required>
                                                        <option>บุคคลธรรมดา</option>
                                                        <option>นิติบุคคล</option>
                                                    </select>
                                                </div>
                                        </div>
                                        <div class="form-group">
                                                <label for="inputEmail3" class="col-sm-2 control-label">Package</label>
                                                <div class="col-md-4">
                                                    <select class="form-control" id="cm_package"name="cm_package" required>
                                                        <option>1,500 บาท Download 20 Mbps / Upload  3 Mbps</option>
                                                        <option>2,000 บาท Download 25 Mbps / Upload  3 Mbps</option>
                                                        <option>2,500 บาท Download 30 Mbps / Upload  5 Mbps</option>
                                                        <option>3,000 บาท Download 35 Mbps / Upload  5 Mbps</option>
                                                        <option>3,500 บาท Download 40 Mbps / Upload  5 Mbps</option>
                                                    </select>
                                                </div>
                                         </div>
                                        <div class="form-group">
                                            <label for="inputPassword3" class="col-sm-2 control-label">ชื่อ</label>
                                            <div class="col-sm-3">
                                                <input type="text" class="form-control" name="cm_fname" value="<? echo $user['cm_fname']?>" required>
                                            </div>
                                        </div>                                      
                                        <div class="form-group">
                                            <label for="inputEmail3" class="col-sm-2 control-label">นามสกุล</label>
                                            <div class="col-lg-4">
                                                <input type="text" class="form-control" name="cm_lname"  value="<? echo $user['cm_lname']?>" required>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="inputPassword3" class="col-sm-2 control-label">หมายเลขบัตรประชาชน</label>
                                            <div class="col-lg-4">
                                                <input type="text" class="form-control" name="cm_idcard"  value="<? echo $user['cm_idcard']?>" required>
                                            </div>
                                        </div>    
                                        <div class="form-group">
                                            <label for="inputEmail3" class="col-sm-2 control-label">เบอร์โทรศัพท์</label>
                                            <div class="col-lg-4">
                                                <input type="text" class="form-control" name="cm_tel"  value="<? echo $user['cm_tel']?>" required>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="inputPassword3" class="col-sm-2 control-label">email</label>
                                            <div class="col-lg-4">
                                                <input type="email" class="form-control" name="cm_email"  value="<? echo $user['cm_email']?>" >
                                            </div>
                                        </div>                                   
                                        <div class="form-group">
                                            <label for="inputEmail3" class="col-sm-2 control-label">ที่อยู่</label>
                                            <div class="col-lg-4">
                                                <input type="text" class="form-control" name="cm_addr"  value="<? echo $user['cm_addr']?>" >
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="inputPassword3" class="col-sm-2 control-label">ตำบล</label>
                                            <div class="col-lg-4">
                                                <input type="text" class="form-control" name="cm_tambon"  value="<? echo $user['cm_tambon']?>" >
                                            </div>
                                        </div>                                      
                                        <div class="form-group">
                                            <label for="inputEmail3" class="col-sm-2 control-label">อำเภอ</label>
                                            <div class="col-lg-4">
                                              <input type="text" class="form-control" name="cm_amphor"  value="<? echo $user['cm_amphor']?>" >
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="inputPassword3" class="col-sm-2 control-label">จังหวัด</label>
                                            <div class="col-lg-4">
                                                <input type="text" class="form-control" name="cm_province"  value="<? echo $user['cm_province']?>" >
                                            </div>
                                        </div>    
                                </div> <!--tab pane-->
                                        <div class="tab-pane fade" id="map">
                                            <div class="form-group">
                                                <label for="inputPassword3" class="col-sm-2 control-label">latitude</label>
                                            <div class="col-lg-4">
                                                <input type="text" class="form-control" id="latitude" name="latitude"  value="<? echo $area['latitude']?>" readonly="readonly">
                                            </div>
                                        </div>   
                                        <div class="form-group">
                                            <label for="inputPassword3" class="col-sm-2 control-label">longtitude</label>
                                            <div class="col-lg-4">
                                                <input type="text" class="form-control" id="longtitude" name="longtitude"  value="<? echo $area['longtitude']?>" readonly="readonly">
                                            </div>
                                        </div> 
                                        <div id="map_canvas"></div> </br>
                                    </div> 
                            </div> <!-- tab content -->                                
                                      <div class="form-group">
                                        <div class="col-sm-offset-2 col-sm-10">
                                          <button type="submit" class="btn btn-primary"><?=($profile==TRUE ? 'พิมพ์รายงาน' : 'บันทึกข้อมูล');?></button>
                              			  <input type="hidden" name="cm_id" value="<? echo $user['cm_id']?>">
                                        </div>
                                      </div>
                                </form>
                            </div><!-- /.row -->
                        </div><!--panel body-->
                    </div><!--panel primary-->     
                </div><!---clo-lg-12--> 
            </div><!--row-->
</div>      <!-- /#page-wrapper -->
<script type="text/javascript">  
var map;
var GGM;
var my_Marker;

function initialize() {
    GGM=new Object(google.maps); 
	infoWindow = new google.maps.InfoWindow();
    // กำหนดจุดเริ่มต้นของแผนที่  
    var my_Latlng  = new GGM.LatLng(<?=($area['latitude'] ? $area['latitude'] : 13.761728449950002);?>,<?=($area['longtitude'] ? $area['longtitude'] : 100.6527900695800);?>);  
	
    var my_DivObj=$("#map_canvas")[0];   
    // กำหนด Option ของแผนที่  
    var myOptions = {  
        zoom: 10, 
        center: my_Latlng,
        mapTypeId: GGM.MapTypeId.HYBRID 
    };  
    map = new GGM.Map(my_DivObj,myOptions);
      
    my_Marker = new GGM.Marker({ 
        position: my_Latlng, 
        map: map,
        draggable:<?=($profile==TRUE ? 'false' : 'true');?>, 
        title:"คลิกลากเพื่อหาตำแหน่งจุดที่ต้องการ!"
    });  

    GGM.event.addListener(my_Marker, 'dragend', function() {  
        var my_Point = my_Marker.getPosition(); 
        map.panTo(my_Point);   
        $("#latitude").val(my_Point.lat());   
        $("#longtitude").val(my_Point.lng());  
    });       
 
}  

google.maps.event.addDomListener(window, 'load', initialize);

$(function(){
	$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
		google.maps.event.trigger(map, "resize");
		map.setCenter(my_Marker.getPosition());
	});
	
	<? if($readonly==true){ ?>
		$('#customer_form input').attr('readonly', true);
		$('#customer_form select').attr('readonly', true);
	<? } ?>
	
});


</script>    